<template>
          <div v-show="show3" style="margin : 7px; ">
              <el-form v-model="gather" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
                <el-form-item label="待诊患者名称：" prop="name" ref="queryForm">
                  <el-input
                    v-model="gather.name"
                    ref="input5"
                    placeholder="待诊请输入患者名称"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
                  />
                  <el-form-item>
                    <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                  </el-form-item>
                </el-form-item>
                  <div>
                    <el-button style="border-bottom: none" @click="Myself">本人</el-button>
                    <el-button style="border-bottom: none" @click="Departments">科室</el-button>
                  </div>
                <div style="background-color:rgba(231,244,255,0.68);height: 40px; color: #39a4ff;border-radius: 4px; line-height: 38px ;border:1px solid #d3eaff;">
                  <span style="margin-left: 14px">待诊患者</span>
                </div>
                <el-table v-loading="loading" :data="registrationListStay" @selection-change="handleSelectionChange" @row-click="handleDelete">
                  <el-table-column width="220" label="病历号" align="center" prop="medicalRecordNo" />
                  <el-table-column width="95" label="姓名" align="center" prop="name" />
                  <el-table-column width="80" label="年龄" align="center" prop="patientAgeStr"/>
                </el-table>
                <br/>
                <div style="background-color:rgba(231,244,255,0.68);height: 40px; color: #55d386;border-radius: 4px; line-height: 38px ;border:1px solid #d3eaff;">
                  <span style="margin-left: 14px">诊中患者</span>
                </div>
                <el-table v-loading="loading" :data="registrationListIn" @selection-change="handleSelectionChange" @row-click="handleIn">
                  <el-table-column width="220" label="病历号" align="center" prop="medicalRecordNo" />
                  <el-table-column width="95" label="姓名" align="center" prop="name" />
                  <el-table-column width="80" label="年龄" align="center" prop="patientAgeStr"/>
                </el-table>
                <br/>
                <div style="background-color:rgba(231,244,255,0.68);height: 40px; color: #e9ba69;border-radius: 4px; line-height: 38px ;border:1px solid #d3eaff;">
                  <span style="margin-left: 14px">已诊患者</span>
                </div>
                <el-table v-loading="loading" :data="registrationListAlready" @selection-change="handleSelectionChange">
                  <el-table-column width="220" label="病历号" align="center" prop="medicalRecordNo" />
                  <el-table-column width="95" label="姓名" align="center" prop="name" />
                  <el-table-column width="80" label="年龄" align="center" prop="patientAgeStr"/>
                </el-table>
                <br/>
                <div style="background-color:rgba(231,244,255,0.68);height: 40px; color: #ff7f82;border-radius: 4px; line-height: 38px ;border:1px solid #d3eaff;">
                  <span style="margin-left: 14px">已退患者</span>
                </div>
                <el-table v-loading="loading" :data="registrationListRetreat" @selection-change="handleSelectionChange">
                  <el-table-column width="220" label="病历号" align="center" prop="medicalRecordNo" />
                  <el-table-column width="95" label="姓名" align="center" prop="name" />
                  <el-table-column width="80" label="年龄" align="center" prop="patientAgeStr"/>
                </el-table>
                <!-- 添加或修改就诊(门诊)信息对话框 -->
                <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
                  <el-form ref="form" :model="form" :rules="rules" label-width="95px">
                    <el-form-item label="医生的排班id" prop="skdId">
                      <el-input v-model="form.skdId" placeholder="请输入就诊医生ID开始确诊" style="margin-left: 5px;"/>
                    </el-form-item>
                  </el-form>
                  <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitForm">确 定</el-button>
                    <el-button @click="cancel">取 消</el-button>
                  </div>
                </el-dialog>
              </el-form>
          </div>
</template>

<script>
  import { listRegistration, getRegistration,PatientInquiry ,delRegistration, addRegistration, updateRegistration, exportRegistration } from "@/api/dms/registration";


  export default {
  name: "Registration",
  data() {
    return {
      show3: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 就诊(门诊)信息表格数据
      registrationListStay: [],
      registrationListIn: [],
      registrationListAlready: [],
      registrationListRetreat: [],
      gather:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
       queryParamsStay: {
         status: 1,
         dept_id: null,
         user_id: null,
         name:null
      },
      queryParamsIn: {
        status: 2,
        dept_id: null,
        user_id: null,
        name:null

      },
      queryParamsAlready: {
        status: 3,
        dept_id: null,
        user_id: null,
        name:null
      },
      queryParamsRetreat: {
        status: 4,
        dept_id: null,
        user_id: null,
        name:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      regOutpatient: {
        medicalRecordNo:'',
        name:'',
        patientAgeStr:'',
        gender:'',
        registrationId:'',
        patientId:'',
      },

    };

  },

  mounted() {
    this.Myself();
  },
  methods: {
    /** 查询就诊(门诊)信息列表 */
    getList() {
      this.loading = true;
      listRegistration(this.queryParamsStay).then(response => {
        this.registrationListStay = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getListIn() {
      this.loading = true;
      listRegistration(this.queryParamsIn).then(response => {
        this.registrationListIn = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getListAlready() {
      this.loading = true;
      listRegistration(this.queryParamsAlready).then(response => {
        this.registrationListAlready = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getListRetreat() {
      this.loading = true;
      listRegistration(this.queryParamsRetreat).then(response => {
        this.registrationListRetreat = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //本人按钮
    Myself(){
      this.queryParamsStay.user_id=0;
      this.queryParamsStay.dept_id=null;
      this.queryParamsIn.user_id=0;
      this.queryParamsIn.dept_id=null;
      this.queryParamsAlready.user_id=0;
      this.queryParamsAlready.dept_id=null;
      this.queryParamsRetreat.user_id=0;
      this.queryParamsRetreat.dept_id=null;
      this.getList();
      this.getListIn();
      this.getListAlready();
      this.getListRetreat();
    },
    //科室按钮
    Departments(){
      this.queryParamsStay.user_id=null;
      this.queryParamsStay.dept_id=0;
      this.queryParamsIn.user_id=null;
      this.queryParamsIn.dept_id=0;
      this.queryParamsAlready.user_id=null;
      this.queryParamsAlready.dept_id=0;
      this.queryParamsRetreat.user_id=null;
      this.queryParamsRetreat.dept_id=0;
      this.getList();
      this.getListIn();
      this.getListAlready();
      this.getListRetreat();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        gather:null,
        queryParamsStay:null,
        queryParamsIn:null,
        queryParamsAlready:null,
        queryParamsRetreat:null,
        name:null,
        id: null,
        patientId: null,
        createTime: null,
        endAttendance: null,
        status: 0,
        skdId: null,
        needBook: null,
        bindStatus: 0,
        deptId: null,
        attendanceDate: null,
        patientAgeStr: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.gather.push(this.queryParamsStay)
      this.gather.push(this.queryParamsIn)
      this.gather.push(this.queryParamsAlready)
      this.gather.push(this.queryParamsRetreat)
      for(var i=0;i<this.gather.length;i++){
        this.gather[i].name=this.$refs.input5.value;
      }
      this.getList();
      this.getListIn();
      this.getListAlready();
      this.getListRetreat();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");//将输入框里面清空
      this.$refs.input5.value=null
      this.reset();
      this.handleQuery();//查询按钮的方法
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加就诊(门诊)信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRegistration(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改就诊(门诊)信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRegistration(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addRegistration(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /**就诊按钮操作 */
    handleDelete(row,index) {
      const name = row.name || this.ids;
      this.$confirm('确定开始诊断患者"' + name + '"?', "就诊", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.regOutpatient.patientId =row.patientId;
        this.regOutpatient.name = row.name;
        this.regOutpatient.medicalRecordNo = row.medicalRecordNo;
        this.regOutpatient.gender = row.gender;
        this.regOutpatient.patientAgeStr = row.patientAgeStr;
        this.regOutpatient.registrationId = row.id;
        this.$emit("regOutpatientListen",this.regOutpatient);
        //删除页面数据
        this.registrationListStay.splice(index,1);
        this.registrationListIn.push({
          medicalRecordNo:row.medicalRecordNo,
          name:row.name,
          patientAgeStr:row.patientAgeStr
        })
        //return delRegistration(row);
      })
    },
    /**就诊中按钮操作 */
    handleIn(row) {
      const name = row.name || this.ids;
      this.$confirm('继续诊断患者"' + name + '"?', "就诊中", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.regOutpatient.patientId =row.patientId;
        this.regOutpatient.name = row.name;
        this.regOutpatient.medicalRecordNo = row.medicalRecordNo;
        this.regOutpatient.gender = row.gender;
        this.regOutpatient.patientAgeStr = row.patientAgeStr;
        this.regOutpatient.registrationId = row.id;
        this.$emit("regOutpatientListen",this.regOutpatient);
        // row.status=2;
        // updateRegistration(row);
        // //删除页面数据
        // this.registrationListStay.splice(index,1);
        // this.registrationListIn.push({
        //   medicalRecordNo:row.medicalRecordNo,
        //   name:row.name,
        //   patientAgeStr:row.patientAgeStr
        //})
        //return delRegistration(row);
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParamsStay = this.queryParams;
      this.$confirm('是否确认导出所有就诊(门诊)信息数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportRegistration(queryParamsStay);
      }).then(response => {
        this.download(response.msg);
      }).catch(function() {});
    }
  }
};
</script>
